package com.example.paopao.consumer.memer.controller;

import com.example.paopao.common.pojo.security.CurrenPrincipal;
import com.example.paopao.common.web.JsonResult;
import com.example.paopao.consumer.memer.pojo.vo.JobHiringPhoneVO;
import com.example.paopao.consumer.memer.service.IJobHiringService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 获取联系方式
 */
@RestController
@RequestMapping("/v1/jobs/la/")
public class JobIntegralController {

    @Autowired
    private IJobHiringService iJobHiringService;

    @GetMapping("{id}/gphone")
    @ApiOperation("根据id查找电话号码")
    @PreAuthorize("hasAuthority('/memer/release/person')")
    public JsonResult getPhone(@PathVariable Long id,
                               @AuthenticationPrincipal CurrenPrincipal currenPrincipal){
        JobHiringPhoneVO phone = iJobHiringService.getPhone(id);
        if (phone!=null){
            iJobHiringService.deductIntegral(currenPrincipal.getUserId());
        }
        return JsonResult.ok(phone);
    }
}
